import { combineReducers, legacy_createStore as createStore } from 'redux';
// 配置数据的持久化效果
import { persistReducer, persistStore } from 'redux-persist';
// 导入需要配置的数据源，可以选择，storage，cookie,session等
import storage from 'redux-persist/lib/storage';

import Theme from './reducer/theme';
import { User } from '@/store/reducer/user';

const reducers = combineReducers({
  storeTheme: Theme,
  storeUser: User,
});

// 定义配置的信息
const persistConfig = {
  key: 'witStoreData',
  storage,
  // 如果不想将部分state持久化，可以将其放入黑名单(blacklist)中.黑名单是设置
  // blacklist: []
};

// 创建持久化的配置persist的信息
const persist_reducers = persistReducer(persistConfig, reducers);

// 创建存储对象并且抛出对象
export const store = createStore(persist_reducers);
export const persist = persistStore(store);

export type RootState = ReturnType<typeof store.getState>;
// 调用方式
// const dispatch = useDispatch();

// //    const Loading = useSelector((state) => state.theme.Loading);

// const changeLoadings = () => {
//     dispatch(changeLoading(true));
// }

// const test =  () => {
//     changeLoadings()
// };
